<!DOCTYPE html>
<html>

<head>
    <meta content="telephone=no" name="format-detection">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="Content-Language" content="zh-CN">
    <meta http-equiv="x-ua-compatible" content="IE=edge, chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <meta name="keywords" content="关键词" />
    <meta name="description" content="页面简介" />
    <link rel="icon" href="favicon.ico" />
    <link rel="shortcut icon" href="favicon.ico" />
    <link href="csaa/css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="./csaa/fonts/iconfont/iconfont.css">
    <link rel="stylesheet" href="./csaa/fonts/materialicons/material-icons.css">

    <script language="javascript" type="text/javascript" src="./csaa/js/jquery.min.js"></script>
    <script src="./csaa/js/httpPath.js"></script>
    <script src="./csaa/js/httpUtils.js"></script>
    <script language="javascript" type="text/javascript" src="./csaa/js/site.js"></script>
    <title>全国青少年航空科学素质等级考试</title>
</head>

<body class="register" style="background-color: #efefef;">
    <!-- 头部 开始 -->
    <div class="header login_header">

    </div>
    <!-- 头部 结束 -->




    <!-- 主体 开始 -->
    <div id="register_main">
        <div class="register_content limitwidth register_kaodian_form">

            <div class="form_box">
                <form id="register_form" autocomplete="off">
                    <div class="part_title">重置密码</div>
                    <div class="form_group">
                        <label class="form_label">
						  <div class="cn"><span class="star">*</span>用户名</div>
						</label>
                        <div class="form_item_con">
                            <input type="text" class="form_input rowwidth_30" name="userName">
                        </div>
                    </div>
                    <div class="form_group">
                        <label class="form_label">
						  <div class="cn"><span class="star">*</span>找回方式</div>
						</label>
                        <div class="form_item_con">
                            <select class="form_input form_select rowwidth_20" placeholder="" name="bisType" id="bisType">
                                <option value="">请选择找回方式</option>
                                <option value="1">手机号</option>
                                <option value="2">邮箱</option>
                            </select>
                        </div>
                    </div>
                    <div class="form_group_phone" style="display: none;">
                        <div class="form_group">
                            <label class="form_label">
                            <div class="cn"><span class="star">*</span>手机号</div>
                            </label>
                            <div class="form_item_con">
                                <input type="text" class="form_input rowwidth_30" name="phone">
                            </div>
                        </div>
                    </div>
                    <div class="form_group_email" style="display: none;">
                        <div class="form_group">
                            <label class="form_label">
                            <div class="cn"><span class="star">*</span>电子邮箱</div>
                            </label>
                            <div class="form_item_con">
                                <input type="text" class="form_input rowwidth_30" name="email">
                            </div>
                        </div>
                    </div>
                    <div class="form_group form_group_code" style="display: none;">
                        <label class="form_label">
                        <div class="cn"><span class="star">*</span>验证码</div>
                        </label>
                        <div class="form_item_con">
                            <div class="form_row">
                                <input type="text" class="form_input rowwidth_10" name="enroll_verification_code">
                                <a id="btn_verification" class="btn btn_color_1 btn_primary">获取验证码</a>
                            </div>
                        </div>
                    </div>
                    <div class="form_group_password">
                        <div class="form_group">
                            <label class="form_label">
                            <div class="cn"><span class="star">*</span>新密码</div>
                            </label>
                            <div class="form_item_con">
                                <input type="password" class="form_input rowwidth_30" name="passWord">
                            </div>
                        </div>
                    </div>

                    <div class="form_group form_manage">
                        <label class="form_label"></label>
                        <div class="form_item_con">
                            <div class="manage_wrap">
                                <a id="btn_sumbit" class="btn btn_color_1 btn_sumbit">重置密码</a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>

        </div>
        <div class="footer">@ 全国青少年无人机科学素质等级考试</div>

    </div>
    <!-- 主体 结束 -->

    <script>
        //选择验证方式
        $(document).on("change", "#bisType", function() {
            if ($(this).val() == 1) {
                $(".form_group_phone").show();
                $(".form_group_code").show();
                $(".form_group_email").hide();
            } else if ($(this).val() == 2) {
                $(".form_group_phone").hide();
                $(".form_group_email").show();
                $(".form_group_code").show();
            } else {
                $(".form_group_phone").hide();
                $(".form_group_email").hide();
                $(".form_group_code").hide();
            }
        })

        //短信验证
        $(document).on("click", "#btn_verification", function(e) {

            var tmp_this = $(this);

            if (tmp_this.hasClass("disabled")) {
                return false;
            } else {

                if ($("#bisType").val() == 1) {
                    var phone = $('[name=phone]').val();
                    if (!phone.match(/^1[3456789][0-9]{9}$/)) {
                        $.fn.winktips("请输入11位有效手机号");
                        return false;
                    }

                    $.post(GET_verifyCode, {
                        "phone": phone
                    }, function(data) {
                        if (data.status == 1) {
                            $.fn.winktips(data.msg);
                            $('[name=kaowu_phone]').attr("readonly", "readonly");
                            var InterValObj; //timer变量，控制时间
                            var curCount = 60; //当前剩余秒数
                            //timer处理函数
                            function SetRemainTime() {
                                if (curCount == 0) {
                                    window.clearInterval(InterValObj); //停止计时器
                                    tmp_this.removeClass("disabled").html("重发验证码"); //启用按钮
                                    $('[name=kaowu_phone]').removeAttr("readonly");
                                } else {
                                    curCount--;
                                    tmp_this.html(curCount + "秒后重发");
                                }
                            }
                            tmp_this.addClass("disabled").html(curCount + "秒后重发");
                            InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次
                        }
                        if (data.status == 0) {
                            $.fn.winktips(data.msg);
                        }

                    }, "json");
                }
                if ($("#bisType").val() == 2) {
                    var mailto = $("[name=email]").val(); //mailto:644182999@qq.com?subject=邮件标题&body=邮件内容
                    var emailreg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); //正则表达式


                    var tmp_parms = {
                        "email": $("[name=email]").val() //邮箱
                    };

                    if (!mailto || !emailreg.test(mailto)) {
                        $.fn.winktips("请正确输入电子邮箱");
                        fun_tipshighlight_scroll($("[name=email]"));
                        $("[name=email]").focus();
                        return false;
                    }

                    //$("#btn_verification").attr("href", "111");

                    //获取邮箱验证码ajax
                    $.ajax({
                        type: "POST",
                        url: GET_getEmailCode,
                        dataType: "json",
                        data: tmp_parms,
                        timeout: 20000,
                        beforeSend: function(XMLHttpRequest) {
                            tmp_this.addClass("disabled").text("获取中……");
                        },
                        success: function(data, textStatus) {
                            if (data.status == 1) {



                            }
                        },
                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                            $.fn.winktips("连接超时，请检查您的网络");
                        },
                        complete: function() {
                            tmp_this.removeClass("disabled").text("获取验证码");
                        }
                    });

                }

            }
        });


        //表单错误滚动到相应位置
        function fun_tipshighlight_scroll($tipshighlight_target) {
            if (typeof $tipshighlight_target == "object" && $tipshighlight_target.length) {
                $("html, body").animate({
                    scrollTop: $tipshighlight_target.offset().top - 200
                }, "fast");
            }
        }


        //提交
        $("#btn_sumbit").on('click', function() {
            var $this_btn = $(this);

            var tmp_parms = {
                "userName": $("[name=userName]").val(), //用户名
                "bisType": $("[name=bisType]").val(), //方式
                "code": $("[name=enroll_verification_code]").val(), //验证码
                "passWord": $("[name=passWord]").val() //密码
            };


            //用户名
            if (!$("[name=userName]").val()) {
                $.fn.winktips("请输入用户名");
                fun_tipshighlight_scroll($("[name=userName]"));
                $("[name=userName]").focus();
                return false;
            }
            //方式
            if (!$("[name=bisType]").val()) {
                $.fn.winktips("请先选择验证方式");
                fun_tipshighlight_scroll($("[name=bisType]"));
                $("[name=bisType]").focus();
                return false;
            }
            if ($("#bisType").val() == 1) {
                //手机号
                if (!$("[name=phone]").val() || !$("[name=phone]").val().match(/^1[3456789][0-9]{9}$/)) {
                    $.fn.winktips("请正确输入联系人手机号");
                    fun_tipshighlight_scroll($("[name=phone]"));
                    $("[name=phone]").focus();
                    return false;
                }
            }
            if ($("#bisType").val() == 2) {
                var emailreg = new RegExp("^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$"); //正则表达式
                //电子邮箱
                if (!$("[name=email]").val() || !emailreg.test($("[name=email]").val())) {
                    $.fn.winktips("请正确输入电子邮箱");
                    fun_tipshighlight_scroll($("[name=email]"));
                    $("[name=email]").focus();
                    return false;
                }
            }
            //验证码
            if (!$("[name=enroll_verification_code]").val()) {
                $.fn.winktips("请输入短信验证码");
                fun_tipshighlight_scroll($("[name=enroll_verification_code]"));
                $("[name=enroll_verification_code]").focus();
                return false;
            }
            //console.log(tmp_parms)
            $.ajax({
                type: "POST",
                url: GET_Retrievepassword,
                dataType: "json",
                data: tmp_parms,
                timeout: 20000,
                beforeSend: function(XMLHttpRequest) {
                    $this_btn.addClass("disabled").text("提交中……");
                },
                success: function(data, textStatus) {
                    if (data.status == 1) {

                        $.fn.poptips({
                            title: "重置成功", //默认为空
                            con: "是否前往登录？",
                            conCenter: false, //文本内容内容是否居中，默认居中
                            //btnOK: false, //是否显示确认按钮 默认显示
                            btnCancel: true, //是否显示取消按钮 默认不显示
                            btnOKText: "去登录", //确认按钮的文案
                            btnCancelText: "去首页", //取消按钮的文案
                            btnOKClick: function() { //确认按钮点击事件（没有按钮时遵从此事件）
                                window.location.href = "./login.html";
                            },
                            btnCancelClick: function() { //取消按钮点击事件
                                window.location.href = "./index.html";
                            }
                        });


                    } else if (data.status == 0) {
                        $.fn.winktips(data.msg);
                    } else {
                        $.fn.winktips("重置失败");
                    }
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    $.fn.winktips("连接超时，请检查您的网络");
                },
                complete: function() {
                    $this_btn.removeClass("disabled").text("重置密码");
                }
            });

        })
    </script>
</body>

</html>
